home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-13 | 12.5 KB | 427 lines | [TEXT/ds30] |
- /*
- execute file "AdminHelp";
-
- SIMPLE SERVER MANAGEMENT MODEL
- ==============================
- */
-
- /* ******************************************************************************************** */
- /* DEVICES */
- /* ******************************************************************************************** */
-
- execute file "DeviceHelp";
-
- /* ******************************************************************************************** */
- /* LOCATIONS */
- /* ******************************************************************************************** */
-
- PROCEDURE help_locations()
- {
- print "";
- print "LOCATIONS:";
- print "----------";
- print "These locations indicate where all new databases and logs files are";
- print "placed. Devices can be selected for the data and index files of all";
- print "new databases. A single device can be selected for placing new online";
- print "log files. Two devices can be selected for the restart files.";
- print "";
- print "PROCEDURE list_locations()";
- print "List all locations that have been set.";
- print "";
- print "PROCEDURE set_database_location(devicename [, path ])";
- print "Set the both data and index location for new databases.";
- print "";
- print "PROCEDURE set_log_location(devicename [, path ])";
- print "Set the location for new log files.";
- print "";
- print "PROCEDURE set_log_archive_location(devicename [, path ])";
- print "Set the location for archived log files.";
- print "";
- print "PROCEDURE set_restart_locations(devicea, deviceb)";
- print "Set the locations for the restart files.";
- print "";
- print "PROCEDURE set_data_location(devicename [, path ])";
- print "Set the data location for new databases.";
- print "";
- print "PROCEDURE set_index_location(devicename [, path ])";
- print "Set the index location for all new databases.";
- print "";
- } END PROCEDURE help_locations;
-
- PROCEDURE check_name(name)
- RETURNS boolean;
- ARGUMENT generic name;
- {
- if (name is null or ($typeof(name) != $varchar and $typeof(name) != $char))
- return($FALSE);
- return($TRUE);
- } END PROCEDURE check_name;
-
- PROCEDURE find_location(name, print_error)
- RETURNS integer;
- ARGUMENT generic name = $null;
- ARGUMENT boolean print_error = $TRUE;
- {
- if (not check_name(name)) {
- print "ERROR: Please specify the name of a location.";
- return(0);
- }
-
- open_master;
- select * from $sm_master!syslocations
- where .name = name
- order by id
- into $sm_cursor1 for extract;
- if ($rows($sm_cursor1) == 0) {
- if (print_error)
- print "ERROR: A location called '" + name + "' does not exists.";
- return(0);
- }
-
- fetch first of $sm_cursor1;
- return($sm_cursor1->id);
- } END PROCEDURE find_location;
-
- PROCEDURE set_location(devicename, path, locationname, locationtype, storetype)
- RETURNS boolean;
- ARGUMENT generic devicename = $null, path = $null;
- ARGUMENT varchar locationname, locationtype, storetype = "FutureStorage";
- {
- integer dev_id;
- integer loc_id;
-
- if (not check_name(devicename)) {
- print "ERROR: Please specify the name of a device.";
- return($FALSE);
- }
-
- if (path is null)
- dev_id = find_device(devicename);
- else {
- if (not check_name(path)) {
- print "ERROR: You may only specify a file-system path after the device name.";
- return($FALSE);
- }
- dev_id = add_device(devicename, path);
- }
- if (dev_id == 0)
- return($FALSE);
-
- loc_id = find_location(locationname, $FALSE);
- if (loc_id == 0)
- ADD LOCATION (locationname, locationtype, storetype, dev_id);
- else
- ALTER LOCATION (loc_id, DEVICEID = dev_id);
- return($TRUE);
- } END PROCEDURE set_location;
-
- PROCEDURE set_data_location(devicename, path)
- RETURNS boolean;
- ARGUMENT generic devicename = $null, path = $null;
- {
- return(set_location(devicename, path, "DatabaseDataFiles", "Data"));
- } END PROCEDURE set_data_location;
-
- PROCEDURE set_index_location(devicename, path)
- RETURNS boolean;
- ARGUMENT generic devicename = $null, path = $null;
- {
- return(set_location(devicename, path, "DatabaseIndexFiles", "Index"));
- } END PROCEDURE set_index_location;
-
- PROCEDURE set_database_location(devicename, path)
- RETURNS boolean;
- ARGUMENT generic devicename = $null, path = $null;
- {
- integer dev_id;
-
- if (set_data_location(devicename, path))
- return(set_index_location(devicename));
- return($FALSE);
- } END PROCEDURE set_database_location;
-
- PROCEDURE set_log_location(devicename, path)
- RETURNS boolean;
- ARGUMENT generic devicename = $null, path = $null;
- {
- return(set_location(devicename, path, "LogFiles", "log"));
- } END PROCEDURE set_log_location;
-
- PROCEDURE set_log_archive_location(devicename, path)
- RETURNS boolean;
- ARGUMENT generic devicename = $null, path = $null;
- {
- return(set_location(devicename, path, "ArchiveLogFiles", "log","FutureBackup"));
- } END PROCEDURE set_log_archive_location;
-
-
- PROCEDURE set_restart_locations(devicea, deviceb)
- RETURNS boolean;
- ARGUMENT varchar devicea, deviceb;
- {
- print "NOTE: This function call will not have the correct affect unless you place";
- print "the restart files in the locations specified on input. If the server currently";
- print "has one restart file, move it the first location specified here. If the";
- print "server already has two restart files, place them in the locations specified";
- print "here as input.";
- print "";
- print "WARNING! If this function fails, the transaction manager may be remain down.";
- print "If this is the case, move the restart file/s back to where it was and enter:";
- print "server restart;";
- print "";
- trans shutdown;
- server restart in location device_path(find_device(devicea)), device_path(find_device(devicea));
- } END PROCEDURE set_restart_locations;
-
- PROCEDURE list_locations()
- {
- open_master;
- select l.name, d.name as device, path
- from $sm_master!syslocations as l, $sm_master!sysdevices as d
- where FilePurpose = "FutureStorage"
- and Allocation = "Automatic"
- and l.DeviceID = d.ID
- into $sm_cursor1 for extract;
- print 'Name: Device: Path:';
- print '----------------------- ----------------------- ----------------------------';
- for each $sm_cursor1
- print $format("%-24s%-24s%s", $sm_cursor1->name, $sm_cursor1->device, $sm_cursor1->path);
- } END PROCEDURE list_locations;
-
- /* ******************************************************************************************** */
- /* PARTITIONS */
- /* ******************************************************************************************** */
-
- PROCEDURE help_partitions()
- {
- print "";
- print "PARTITIONS:";
- print "-----------";
- print "Existing databases are located on partitions.";
- print "";
- print "PROCEDURE list_partitions([ dbname ])";
- print "List partition of a particular database (or all databases if";
- print "database name ommitted).";
- print "";
- print "PROCEDURE add_database_partition(dbname, devicename)";
- print "Place both data and index files on a particular device.";
- print "";
- print "PROCEDURE remove_database_partition(dbname, devicename)";
- print "No longer locate a database on a particular device.";
- print "";
- print "PROCEDURE add_data_partition(dbname, devicename)";
- print "Place the data files of a database on a particular device";
- print "";
- print "PROCEDURE add_index_partition(dbname, devicename)";
- print "Place the index files on the given database and the given device.";
- print "";
- print "PROCEDURE remove_data_partition(dbname, devicename)";
- print "Remove a data partition of a particular database.";
- print "";
- print "PROCEDURE remove_index_partition(dbname, devicename)";
- print "Remove an index partition from a particular database.";
- print "";
- } END PROCEDURE help_partitions;
-
- PROCEDURE find_database(name, print_error)
- RETURNS integer;
- ARGUMENT varchar name = $null;
- ARGUMENT boolean print_error = $TRUE;
- {
- if (not check_name(name)) {
- print "ERROR: Please specify the name of a database.";
- return(0);
- }
-
- open_master;
- select id
- from $sm_master!sysdatabases
- where .name = :name
- into $sm_cursor1 for extract;
- if ($rows($sm_cursor1) == 0) {
- if (print_error)
- print "ERROR: A database called '" + name + "' does not exists.";
- return 0;
- }
-
- fetch first of $sm_cursor1;
- return($sm_cursor1->id);
-
- } END PROCEDURE find_database;
-
- PROCEDURE find_partition(db_id, dev_id)
- RETURNS integer;
- ARGUMENT integer db_id, dev_id;
- {
- open_master;
- select id
- from $sm_master!syspartitions
- where databaseid = db_id
- and deviceid = dev_id
- into $sm_cursor1 for extract;
- if ($rows($sm_cursor1) == 0)
- return(0);
- fetch first of $sm_cursor1;
- return($sm_cursor1->id);
- } END PROCEDURE find_partition;
-
- PROCEDURE alter_partition(dbname, devicename, data, index)
- RETURNS integer;
- ARGUMENT varchar dbname, devicename;
- ARGUMENT boolean data, index;
- {
- integer db_id;
- integer dev_id;
- integer part_id;
-
- db_id = find_database(dbname);
- if (db_id == 0)
- return(0);
-
- dev_id = find_device(devicename);
- if (dev_id == 0)
- return(0);
-
- part_id = find_partition(db_id, dev_id);
- if (part_id == 0) {
- if (data is null)
- data = $FALSE;
- if (index is null)
- index = $FALSE;
- if (data or index) {
- ADD PARTITION (db_id, dev_id, data = data, index = index, blob = $FALSE);
- part_id = find_partition(db_id, dev_id);
- }
- }
- else {
- if (data is not null)
- ALTER PARTITION (part_id, data = data);
- if (index is not null)
- ALTER PARTITION (part_id, index = index);
-
- select * from $sm_master!syspartitions
- where id = part_id
- into $sm_cursor1 for extract;
- if ($rows($sm_cursor1) == 0)
- return(0);
- fetch first of $sm_cursor1;
- if (not $sm_cursor1->data and
- not $sm_cursor1->index and
- not $sm_cursor1->blob)
- REMOVE PARTITION (part_id);
- }
- return(part_id);
- } END PROCEDURE alter_partition;
-
- PROCEDURE add_data_partition(dbname, devicename)
- RETURNS integer;
- ARGUMENT generic dbname, devicename;
- {
- return(alter_partition(dbname, devicename, $TRUE, $NULL));
- } END PROCEDURE add_data_partition;
-
- PROCEDURE add_index_partition(dbname, devicename)
- RETURNS integer;
- ARGUMENT generic dbname, devicename;
- {
- return(alter_partition(dbname, devicename, $NULL, $TRUE));
- } END PROCEDURE add_index_partition;
-
- PROCEDURE add_database_partition(dbname, devicename)
- RETURNS integer;
- ARGUMENT generic dbname, devicename;
- {
- if (add_data_partition(dbname, devicename) != 0)
- return(add_index_partition(dbname, devicename));
- return(0);
- } END PROCEDURE add_database_partition;
-
- PROCEDURE remove_data_partition(dbname, devicename)
- RETURNS integer;
- ARGUMENT generic dbname, devicename;
- {
- return(alter_partition(dbname, devicename, $FALSE, $NULL));
- } END PROCEDURE remove_data_partition;
-
- PROCEDURE remove_index_partition(dbname, devicename)
- RETURNS integer;
- ARGUMENT generic dbname, devicename;
- {
- return(alter_partition(dbname, devicename, $NULL, $FALSE));
- } END PROCEDURE remove_index_partition;
-
- PROCEDURE remove_database_partition(dbname, devicename)
- RETURNS integer;
- ARGUMENT generic dbname, devicename;
- {
- if (remove_data_partition(dbname, devicename) != 0)
- return(remove_index_partition(dbname, devicename));
- return(0);
- } END PROCEDURE remove_database_partition;
-
- PROCEDURE list_partitions(dbname)
- ARGUMENT varchar dbname = "*";
- {
- open_master;
- select db.name as dbname, dev.name as devname, part.data, part.index, part.blob
- from $sm_master!syspartitions as part,
- $sm_master!sysdatabases as db,
- $sm_master!sysdevices as dev
- where db.name like dbname
- and part.backupid is null
- and part.databaseid = db.id
- and part.deviceid = dev.id
- order by db.name
- into $sm_cursor1 for extract;
- if ($rows($sm_cursor1) == 0) {
- print "ERROR: A database called '" + dbname + "' does not exists.";
- return;
- }
-
- print 'Database: Device: Data: Index:';
- print '----------------------- ----------------------- ------------ -----------';
- for each $sm_cursor1 {
- if (not $sm_cursor1->data and
- not $sm_cursor1->index and
- $sm_cursor1->blob)
- continue;
- printf("%-24s%-24s", $sm_cursor1->dbname, $sm_cursor1->devname);
- if ($sm_cursor1->data)
- printf("YES ");
- else
- printf(" - ");
- if ($sm_cursor1->index)
- print "YES ";
- else
- print " - ";
- }
- } END PROCEDURE list_partitions;
-
- /* ******************************************************************************************** */
- /* HELP */
- /* ******************************************************************************************** */
-
- PROCEDURE help_all()
- {
- help_devices;
- help_locations;
- help_partitions;
- } END PROCEDURE help_all;
-
- PROCEDURE help()
- {
- print "";
- print "SERVER ADMINSTRATION:";
- print "---------------------";
- print "The folowing help functions are available:";
- print "help_devices;";
- print "help_locations;";
- print "help_partitions;";
- print "help_all;";
- print "";
- } END PROCEDURE help;
-
- print "Server adminstration help functions defined.";
- print "Enter: 'help;' for help.";
-
-